package com.wzw.basics.operator;

/**
 * @author Wangzhiwen
 */
public class Auto {

    public static void main(String[] args) {
        Increment.test();
        System.out.println();
        Increment2.test();
        System.out.println();
        Subtract.test();
    }

    /**
     * i++ ++在后面表示先赋值在运算
     * ++i ++在前面表示先运算在赋值
     * 自增运算
     */
    public static class Increment {
        public static void test() {
            int i = 1;
            i = i++; // i -> i, i++=1, i -> i
            System.out.println("i=" + i); // 1
            int j = i++; // j=1 i=2
            System.out.println("j=" + j + " i=" + i); // 1 2
            int k = i + ++i * i++; // i + ( (++i) * (i++) ) -> 2 + ( 3 * 3 )
            System.out.println("i=" + i); // i=4
            System.out.println("j=" + j); // j=1
            System.out.println("k=" + k); // k=11
        }
    }

    public static class Increment2 {
        public static void test() {
            int i1 = 10;
            int i2 = 20;
            int i = i1++; // i=10, i1= 11
            System.out.println("i=" + i); // i=10
            System.out.println("i1=" + i1);// i1=11
            i = ++i1; // i=12, i1=12
            System.out.println("i=" + i);// i=12
            System.out.println("i1=" + i1);//i1=12
            i = i2--; // i=20, i2=19
            System.out.println("i=" + i);// i=20
            System.out.println("i2=" + i2);// i2=19
            i = --i2; // i=18, i2=18
            System.out.println("i=" + i);//i=18
            System.out.println("i2=" + i2);//i2=18
        }
    }

    /**
     * 自减运算
     */
    public static class Subtract {
        public static void test() {
            boolean a = false;
            if (a = true) {
                System.out.println(a);
            }
        }
    }

}
